package com.huawei.esdk.tp.professional.local.impl.service;

import java.util.List;
import org.apache.log4j.Logger;
import com.huawei.esdk.tp.professional.local.bean.OrganizationItemEx;
import com.huawei.esdk.tp.professional.local.bean.QueryOrganizationEx;
import com.huawei.esdk.tp.professional.local.bean.QueryOrganizationExResponse;
import com.huawei.esdk.tp.professional.local.bean.TPProfessionalOrgaMgr;
import com.huawei.esdk.tp.professional.local.bean.TPSDKResponseEx;
import com.huawei.esdk.tp.professional.local.impl.utils.ClientProvider;
import com.huawei.esdk.tp.professional.local.impl.utils.ExceptionUtils;
import com.huawei.esdk.tp.professional.local.organization.OrganizationServiceEx;

public class OrganizationServiceExImpl implements OrganizationServiceEx
{
    private static final Logger LOGGER = Logger.getLogger(OrganizationServiceExImpl.class);
    
    private TPProfessionalOrgaMgr tpProfessionalOrgaMgr =
        (TPProfessionalOrgaMgr)ClientProvider.getClient(TPProfessionalOrgaMgr.class);
    
    private static OrganizationServiceExImpl instance = null;
    
    public static synchronized OrganizationServiceExImpl getInstance()
    {
        if (null == instance)
        {
            instance = new OrganizationServiceExImpl();
        }
        return instance;
    }
    
    public TPSDKResponseEx<List<OrganizationItemEx>> queryOrganizationEx()
    {
        LOGGER.info("queryOrganizationEx method start");
        TPSDKResponseEx<List<OrganizationItemEx>> resp = new TPSDKResponseEx<List<OrganizationItemEx>>();
        QueryOrganizationExResponse response = null;
        try
        {
            QueryOrganizationEx parameters = new QueryOrganizationEx();
            response = tpProfessionalOrgaMgr.queryOrganizationEx(parameters);
        }
        catch (Exception e)
        {
            LOGGER.error("queryOrganizationEx method exception");
            ExceptionUtils.processSoapException(resp, e);
            return resp;
        }
        Integer resultCode = response.getResultCode();
        resp.setResult(0 == resultCode ? response.getOrgs() : null);
        resp.setResultCode(resultCode);
        LOGGER.info("queryOrganizationEx method end");
        return resp;
    }
}
